package joodin.impl.util;

import joodin.impl.application.util.ApplicationWrapper;

import org.vaadin.cssinject.CSSInject;

import com.vaadin.ui.Component;

public class ColorUtil {
	
	public ColorUtil() {
	}		
	
	public static void setForegroundColor(final int red, final int green ,final int blue,final Component comp){
		comp.removeStyleName("foregroundColor-" + comp.hashCode());
		String style = ".foregroundColor-" + comp.hashCode() + " { color: rgb(" + red +"," + green + ", " + blue + "); }";
		CSSInject css = ApplicationWrapper.getCSSInjector();
		if(!css.getValue().contains(style)){
			css.setValue(css.getValue() + style);
		}
		comp.addStyleName("foregroundColor-" + comp.hashCode());
	}
	
	public static void setBackgroundColor(final int red, final int green ,final int blue,final Component comp){
		comp.removeStyleName("backgroundColor-" + comp.hashCode());
		String style = ".backgroundColor-" + comp.hashCode() + " { background-color: rgb(" + red +"," + green + ", " + blue + "); }";
		CSSInject css = ApplicationWrapper.getCSSInjector();
		if(!css.getValue().contains(style)){
			css.setValue(css.getValue() + style);
		}
		comp.addStyleName("backgroundColor-" + comp.hashCode());
	}

}
